package wang.chunfan.springcloud.learning.feign.server.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import wang.chunfan.springcloud.learning.feign.server.feign.UserFeign;
import wang.chunfan.springcloud.learning.feign.server.model.Result;
import wang.chunfan.springcloud.learning.feign.server.model.User;

import java.util.List;

/**
 * @version 1.0
 * @Author wangchunfan
 * @Date 2020/5/23 21:05
 **/
@RestController
@RequestMapping("/user")
public class UserFeignController {
    @Autowired
    private UserFeign userFeign;

    @PostMapping
    public Result insert(@RequestBody User user) {
        return userFeign.insert(user);
    }

    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Long id) {
        return userFeign.delete(id);
    }

    @PutMapping
    public Result update(@RequestBody User user) {
        return userFeign.update(user);
    }

    @GetMapping("/{id}")
    public Result get(@PathVariable Long id) {
        return userFeign.get(id);
    }

    @GetMapping("/list")
    Result<List<User>> list(@RequestParam List<Long> ids) {
        return userFeign.list(ids);
    }

    @GetMapping("/getByUsername/{username}")
    Result<List<User>> getByUsername(@PathVariable String username) {
        return userFeign.getByUsername(username);
    }
}
